import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    goodList: [
      {
        name: '诸葛亮',
        price: 1000,
        num: 1,
        checked: false
      },
      {
        name: '蔡文姬',
        price: 1500,
        num: 1,
        checked: false
      },
      {
        name: '妲己',
        price: 2000,
        num: 1,
        checked: false
      },
      {
        name: '鲁班',
        price: 2200,
        num: 1,
        checked: false
      }
    ]
  },
  getters: {
  },
  mutations: {
    setCheck (state, payload) {
      state.goodList.find(item => item.name === payload.name).checked = payload.checked === 'true' ? 0 : 1
    },
    setNum (state, payload) {
      state.goodList.find(item => item.name === payload.name).num = payload.num
    },
    setDel (state, payload) {
      state.goodList = state.goodList.filter(item => item.name !== payload.name)
    }
  },
  actions: {
  },
  modules: {
  }
})
